package com.heima.wemedia.service.impl;

import com.heima.apis.article.ApArticleClient;
import com.heima.apis.comment.ICommentClient;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dtos.*;
import com.heima.utils.thread.WmThreadLocalUtils;
import com.heima.wemedia.service.WmCommentManageService;
import com.heima.wemedia.service.WmNewsService;
import com.heima.wemedia.service.WmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class WmCommentManageServiceImpl implements WmCommentManageService {

    @Autowired
    private ApArticleClient apArticleClient;

    @Autowired
    private ICommentClient iCommentClient;

    @Autowired
    private WmUserService wmUserService;

    /**
     * 评论管理列表
     * @param dto
     * @return
     */
    @Override
    public ResponseResult findNewsComments(WmFindNewsCommentDto dto) {
        //获取用户id
        Integer wmUserId = WmThreadLocalUtils.getUser().getId();

        return apArticleClient.getCommentManageList(dto,wmUserId);
    }

    /**
     * 打开/关闭评论
     * @param dto
     * @return
     */
    @Override
    public ResponseResult updateCommentStatus(WmUpdateCommentStatusDto dto) {

        return apArticleClient.updateCommentStatus(dto);
    }

    //获取作者id 方法
    private Integer getAuthorId() {
        Integer wmUserId = WmThreadLocalUtils.getUser().getId();
        return wmUserService.getById(wmUserId).getApAuthorId();
    }

    /**
     * 查看文章评论详情
     * @param dto
     * @return
     */
    @Override
    public ResponseResult getCommentList(WmCommentListDto dto) {
        //获取作者id
        Integer apAuthorId = getAuthorId();
        return iCommentClient.getCommentList(dto,apAuthorId);
    }



    /**
     * 作者回复评论
     * @param dto
     * @return
     */
    @Override
    public ResponseResult commentRepay(WmCommentRepayDto dto) {
        //获取作者id
        Integer apAuthorId = getAuthorId();
        dto.setAuthorId(apAuthorId);
        return iCommentClient.commentRepay(dto);
    }

    /**
     * 作者点赞评论/取消点赞
     * @param dto
     * @return
     */
    @Override
    public ResponseResult like(WmCommentLikeDto dto) {
        //获取作者id
        Integer apAuthorId = getAuthorId();
        dto.setAuthorId(apAuthorId);
        return iCommentClient.authorLike(dto);
    }
}
